<template>
    <div class="main">
        <!--用户数量统计-->
        <div class="nav">
            <div class="icon"></div>
            <div class="title">用户数量统计</div>
        </div>
        <div class="statistic">
            <div class="total-number" v-text="userStatisicData.title"></div>
            <div class="list">
                <div class="item" v-for="typeItem in userStatisicData.text">
                    <div class="label"></div>
                    <div class="item-text" v-text="typeItem"></div>
                </div>
            </div>
            <div class="divider"></div>
            <Echarts :options="userStatisicData.option"
                :style="'width:100%;height:' + userStatisicData.height + 'px'" />
        </div>
        <!--互联网平台按照六类划分数据统计-->
        <div class="nav">
            <div class="icon"></div>
            <div class="title">互联网平台按照六类划分数据统计</div>
        </div>
        <div class="statistic">
            <div class="total-number" v-text="netDivide.title"></div>
            <div class="list">
                <div class="item" v-for="typeItem in netDivide.text">
                    <div class="label"></div>
                    <div class="item-text" v-text="typeItem"></div>
                </div>
            </div>
            <div class="divider"></div>
            <Echarts :options="netDivide.option" :style="'width:100%;height:' + netDivide.height + 'px'" />
        </div>
        <!--互联网平台按照三类划分数据统计-->
        <div class="nav">
            <div class="icon"></div>
            <div class="title">互联网平台按照三类划分数据统计</div>
        </div>
        <div class="statistic">
            <div class="total-number" v-text="netThreeDivide.title"></div>
            <div class="list">
                <div class="item" v-for="typeItem in netThreeDivide.text">
                    <div class="label"></div>
                    <div class="item-text" v-text="typeItem"></div>
                </div>
            </div>
            <div class="divider"></div>
            <Echarts :options="netThreeDivide.option" :style="'width:100%;height:' + netThreeDivide.height + 'px'" />
        </div>
    </div>
    <div class="main">
        <div class="nav">
            <div class="icon"></div>
            <div class="title" v-text="platform.title"></div>
        </div>
        <div class="range">
            <div class="range-tab">
                <div :class="{ reply_select: platform.select, reply: !platform.select }" @click="togglePlatformData">
                    及时回复</div>
                <div :class="{ reply_select: !platform.select, reply: platform.select }" @click="togglePlatformData">
                    未及时回复</div>
            </div>
            <div class="divider"></div>
            <div class="item" v-for="(rangeItem, idx) in platform.rangeData" :key="idx">
                <div class="container">
                    <div class="no">
                        <img v-if="idx < 3" :src="Noformat(idx)">
                        <div v-else>{{ idx + 1 }}</div>
                    </div>
                    <div class="info">
                        <div class="content text-overflow" v-text="rangeItem.platformName"></div>
                    </div>
                </div>
                <van-divider v-if="platform.rangeData.length - 1 != idx" />
            </div>

        </div>
        <div class="nav">
            <div class="icon"></div>
            <div class="title" v-text="org.title"></div>
        </div>
        <div class="range">
            <div class="range-tab">
                <div :class="{ reply_select: org.select, reply: !org.select }" @click="toggleOrgData">及时回复</div>
                <div :class="{ reply_select: !org.select, reply: org.select }" @click="toggleOrgData">未及时回复</div>
            </div>
            <div class="divider"></div>
            <div class="item" v-for="(rangeItem, idx) in org.rangeData" :key="idx">
                <div class="container">
                    <div class="no">
                        <img v-if="idx < 3" :src="Noformat(idx)">
                        <div v-else>{{ idx + 1 }}</div>
                    </div>
                    <div class="info">
                        <div class="content text-overflow" v-text="rangeItem.platformName"></div>
                    </div>
                </div>
                <van-divider v-if="org.rangeData.length - 1 != idx" />
            </div>

        </div>
    </div>
</template>
<script lang="ts" setup>
import Echarts from '../../../components/Echarts/index.vue'
import { onMounted, reactive } from 'vue';
// 排行榜
import iconNo1 from '@/assets/imgs/totalPreview/no1.png'
import iconNo2 from '@/assets/imgs/totalPreview/no2.png'
import iconNo3 from '@/assets/imgs/totalPreview/no3.png'
import { getUserStatisic, getKindCount, getThreeKindCount, getPlatformReply, getOrgReply, getPlatformNotReply, getOrgNotReply } from '@/api/department';

//用户数量统计
const userStatisicData = reactive({
    title: '总用户数量',
    text: [] as any,
    height: 96,
    option: {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '3%',
            top: '3%',
            bottom: '0',
            containLabel: true
        },
        legend: {
            show: false
        },
        xAxis: {
            axisLabel: {
                textStyle: {
                    color: "#646464", //X轴文字颜色
                    fontSize: 8,
                }
            }
        },
        yAxis: {
            type: 'category',
            axisTick: {
                show: false,
            },
            axisLabel: {
                textStyle: {
                    color: "#BBBBBB", //Y轴文字颜色
                    fontSize: 8,
                }
            },
            data: ['监管机构', '监管机构用户', '平台企业', '平台企业用户']
        },
        series: [{
            type: 'bar',
            data: [0, 0, 0, 0],
            barCategoryGap: '70%',
            itemStyle: {
                normal: {
                    color: '#4c69dc',
                    barBorderRadius: [0, 20, 20, 0],
                }
            }
        }]
    }
})

const netDivide = reactive({
    title: '六类划分数据总数',
    text: [] as any,
    height: 144,
    option: {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '3%',
            top: '3%',
            bottom: '0',
            containLabel: true
        },
        legend: {
            show: false
        },
        xAxis: {
            axisLabel: {
                textStyle: {
                    color: "#646464", //X轴文字颜色
                    fontSize: 8,
                }
            }
        },
        yAxis: {
            type: 'category',
            axisTick: {
                show: false,
            },
            axisLabel: {
                textStyle: {
                    color: "#BBBBBB", //Y轴文字颜色
                    fontSize: 8,
                }
            },
            data: ['网络销售', '生活服务', '社交娱乐', '信息咨询', '金融服务', '计算应用']
        },
        series: [{
            type: 'bar',
            data: [0, 0, 0, 0, 0, 0],
            barCategoryGap: '70%',
            itemStyle: {
                normal: {
                    color: '#4c69dc',
                    barBorderRadius: [0, 20, 20, 0],
                }
            }
        }]
    }
})

const netThreeDivide = reactive({
    title: '三级划分数据总数',
    text: [] as any,
    height: 72,
    option: {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '3%',
            top: '3%',
            bottom: '0',
            containLabel: true
        },
        legend: {
            show: false
        },
        xAxis: {
            axisLabel: {
                textStyle: {
                    color: "#646464", //X轴文字颜色
                    fontSize: 8,
                }
            }
        },
        yAxis: {
            type: 'category',
            axisTick: {
                show: false,
            },
            axisLabel: {
                textStyle: {
                    color: "#BBBBBB", //Y轴文字颜色
                    fontSize: 8,
                }
            },
            data: ['超级平台', '大型平台', '中小平台']
        },
        series: [{
            type: 'bar',
            data: [0, 0, 0],
            barCategoryGap: '70%',
            itemStyle: {
                normal: {
                    color: '#4c69dc',
                    barBorderRadius: [0, 20, 20, 0],
                }
            }
        }]
    }
})

const platform = reactive({
    title: '平台企业回复数据排行榜',
    select: true,
    rangeData: [] as any
})

const org = reactive({
    title: '监管机构回复数据排行榜',
    select: true,
    rangeData: [] as any
})

const Noformat = (index: any) => {
    switch (index) {
        case 0:
            return iconNo1;
        case 1:
            return iconNo2;
        case 2:
            return iconNo3;
    }
}
onMounted(() => {
    getUserStatisicData()
    getNetworkData()
    getThreeKind()
    getPlatform()
    getOrg()
})

const togglePlatformData = () => {
    platform.select = !platform.select
    if (platform.select) {
        getPlatform()
    } else {
        getPlatformNot()
    }
}

const toggleOrgData = () => {
    org.select = !org.select
    if (org.select) {
        getOrg()
    } else {
        getOrgNot()
    }
}

/**
 * 用户数量统计
 */
const getUserStatisicData = async () => {
    const response = await getUserStatisic()
    const data = response.data
    const textArray = [
        `监管机构-${data.jgjg}`,
        `监管机构用户-${data.jgjgyh}`,
        `平台企业-${data.qypt}`,
        `平台企业用户-${data.qyptyh}`,
    ]
    userStatisicData.text.push(...textArray)
    userStatisicData.title = `总用户数量·${data.zyhsl}`

    var dataDetail = [data.jgjg, data.jgjgyh, data.qypt, data.qyptyh];
    userStatisicData.height = (dataDetail.length - 1) * 20 + dataDetail.length * 4 + 20
    let option = {
        type: 'bar',
        data: dataDetail,
        barCategoryGap: '70%',
        itemStyle: {
            normal: {
                color: '#4c69dc',
                barBorderRadius: [0, 20, 20, 0],
            }
        }
    }
    Object.assign(userStatisicData.option.series[0], option)
}
/**
 * 用户数量统计
 */
const getNetworkData = async () => {
    const response = await getKindCount()
    const data = response.data
    const textArray = [
        `网络销售-${data.wlxs}`,
        `生活服务-${data.shfw}`,
        `社交娱乐-${data.sjyl}`,
        `信息咨询-${data.xxzx}`,
        `金融服务-${data.jrff}`,
        `计算应用-${data.jsyy}`,
    ]
    netDivide.text.push(...textArray)
    netDivide.title = `总用户数量·${data.llhfsjzs}`
    var dataDetail = [data.wlxs, data.shfw, data.sjyl, data.xxzx, data.jrff, data.jsyy];
    netDivide.height = (dataDetail.length - 1) * 20 + dataDetail.length * 4 + 20
    let option = {
        type: 'bar',
        data: dataDetail,
        barCategoryGap: '70%',
        itemStyle: {
            normal: {
                color: '#4c69dc',
                barBorderRadius: [0, 20, 20, 0],
            }
        }
    }
    Object.assign(netDivide.option.series[0], option)
}
/**
 * 用户数量统计
 */
const getThreeKind = async () => {
    const response = await getThreeKindCount()
    const data = response.data
    const textArray = [
        `超级平台-${data.cjpt}`,
        `大型平台-${data.dxpt}`,
        `中小平台-${data.zxxpt}`
    ]
    netThreeDivide.text.push(...textArray)
    netThreeDivide.title = `总用户数量·${data.sjhfsjzs}`
    var dataDetail = [data.cjpt, data.dxpt, data.zxxpt];
    netThreeDivide.height = (dataDetail.length - 1) * 20 + dataDetail.length * 4 + 20
    let option = {
        type: 'bar',
        data: dataDetail,
        barCategoryGap: '70%',
        itemStyle: {
            normal: {
                color: '#4c69dc',
                barBorderRadius: [0, 20, 20, 0],
            }
        }
    }
    Object.assign(netThreeDivide.option.series[0], option)
}

//获取企业(回复)
const getPlatform = async () => {
    const platformData = await getPlatformReply()
    platform.rangeData = platformData.data
}
//获取机构（回复）
const getOrg = async () => {
    const orgData = await getOrgReply()
    org.rangeData = orgData.data
}
//获取企业(未回复)
const getPlatformNot = async () => {
    const platformData = await getPlatformNotReply()
    platform.rangeData = platformData.data
}
//获取机构（未回复）
const getOrgNot = async () => {
    const orgData = await getOrgNotReply()
    org.rangeData = orgData.data
}
</script>
<style lang="scss" scoped>
.main {
    display: flex;
    flex-direction: column;
    padding: 0 12px 16px 12px;
    box-sizing: border-box;

    .nav {
        display: flex;
        align-items: center;
        margin-top: 16px;

        .icon {
            width: 4px;
            height: 16px;
            margin-right: 8px;
            background-color: $primary-color;
        }

        .title {
            font-weight: 700;
            text-align: left;
            color: #181818;
            line-height: 12px;
            font-size: 18px;
        }
    }

    .statistic {
        width: 100%;
        background: #ffffff;
        border-radius: 5px;
        box-shadow: 0.5px 0.87px 4.5px 1px rgba(0, 0, 0, 0.05);
        display: flex;
        flex-direction: column;
        margin: 16px 0 0 0;
        padding: 25px 12px;
        box-sizing: border-box;
        align-items: center;

        .divider {
            width: 100%;
            height: 0.5px;
            margin: 12px 0;
            background: #ececec;
        }

        .total-number {
            width: 251px;
            height: 33px;
            border-radius: 7.5px;
            background-color: #F6F8FF;
            font-size: 14px;
            font-weight: bold;
            color: #1f2e4c;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .list {
            width: 100%;
            display: flex;
            flex-direction: row;

            flex-wrap: wrap;
            margin-top: 15px;
            padding: 0 10px;
            box-sizing: border-box;
            align-content: space-around;

            .item {
                width: 33%;
                display: flex;
                flex-direction: row;
                align-items: center;
                padding: 10px 0;

                .label {
                    width: 3.5px;
                    height: 3.5px;
                    background: #4c69dc;
                    border-radius: 2px;
                    margin-right: 4px;
                    margin-left: 10px;
                }

                .item-text {
                    font-size: 10px;
                    font-family: PingFang SC, PingFang SC-Medium;
                    font-weight: 500;
                    text-align: left;
                    color: #181818;
                }
            }

        }
    }

    .range {
        width: 100%;
        background: #ffffff;
        border-radius: 5px;
        box-shadow: 0.5px 0.87px 4.5px 1px rgba(0, 0, 0, 0.05);
        display: flex;
        flex-direction: column;
        margin: 16px 0 0 0;
        padding: 25px 12px;
        box-sizing: border-box;
        align-items: center;


        .range-tab {
            width: 277px;
            height: 33px;
            display: flex;
            flex-direction: row;
            background: #f6f8ff;


            .reply_select {
                flex: 1;
                height: 100%;
                border-radius: 7.5px;
                background: #4c69dc;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 14px;
                font-family: PingFang SC, PingFang SC-Medium;
                font-weight: bold;
                text-align: center;
                color: #f7f7f7;
            }

            .reply {
                flex: 1;
                height: 100%;
                border-radius: 7.5px;
                background: #f6f8ff;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 14px;
                font-family: PingFang SC, PingFang SC-Medium;
                font-weight: bold;
                text-align: center;
                color: #1F2E4C;
            }
        }

        .divider {
            width: 100%;
            height: 0.5px;
            margin: 25px 0;
            background: #ececec;
        }


        .item {
            width: 100%;

            .container {
                width: 100%;
                display: flex;
                align-items: center;

                .no {
                    margin-right: 9px;

                    img {
                        width: 32px;
                        height: 32px;
                    }

                    div {
                        width: 25px;
                        height: 25px;
                        border-radius: 50%;
                        background-color: #F1F4FF;
                        text-align: center;
                        line-height: 25px;
                        color: $primary-color;
                    }
                }

                .info {
                    flex: 1;

                    .content {
                        font-size: 14px;
                        font-weight: bold;
                        text-align: left;
                        color: #181818;
                        margin-bottom: 6px;
                    }

                    .label {
                        .accept {
                            font-size: 10px;
                            font-weight: bold;
                            text-align: left;
                            color: #646464;
                            margin-right: 26px;
                        }

                        .reply {
                            font-size: 10px;
                            font-weight: bold;
                            text-align: left;
                            color: #646464;
                        }
                    }
                }
            }
        }

    }
}
</style>